import 'package:encrypt/encrypt.dart';
import 'package:pointycastle/asymmetric/api.dart';

class RsaUtil {
  static const String PUBLIC_KEY = '''-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCr8qnVN1Fxrxd0nDEkzbzcUnxi
bR59ds9FtJoGYnqd0zEPMTg30JMoHcjydWbEFolYeVOGeQqG98HTFVhDgyxquvMO
lBsnk5MHnTQIA9TVtaH8n3Qw4SDsvp9OoKIRtJCP9X/jLwunAx6Ohx8HJvidb3gG
Zs7XuczpD28iOMvQEQIDAQAB
-----END PUBLIC KEY-----''';

  static String encrypt(String value) {
//    final publicKey = await parseKeyFromFile<RSAPublicKey>('test/public.pem');
    final parser = RSAKeyParser();
    RSAPublicKey publicKey = parser.parse(PUBLIC_KEY) as RSAPublicKey;
    final encrypter = Encrypter(RSA(publicKey: publicKey));
    return encrypter.encrypt(value).base64;
  }
}
